package fr.afcepf.al22.qualite.data.util;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

import javax.sql.DataSource;

public abstract class Al22DataSource implements DataSource {
	/**
	 * url de connexion a la bdd.
	 */
	private static String url;
	/**
	 * driver de connexion a la bdd.
	 */
	private static String driver;
	/**
	 * user de connexion a la bdd.
	 */
	private static String login;
	/**
	 * password de connexion a la bdd.
	 */
	private static String pass;
	
	static{
		Properties props = new Properties();
		
		try {
			InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("al22.properties");
			props.load(is);
			url = props.getProperty("url");
			driver= props.getProperty("driver");
			Class.forName(driver);
			login = props.getProperty("login");
			pass = props.getProperty("pass");
			
			
		} catch (IOException | ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	@Override
	public Connection getConnection() throws SQLException {
		Connection cnx = null;
		cnx = DriverManager.getConnection(url,login, pass);
		return cnx;
	}

	@Override
	public Connection getConnection(String paramUsername, String paramPassword)
			throws SQLException {
		// TODO Auto-generated method stub
		return null;
	}

}
